package com.cl.short_video_java.web.video;

import com.cl.short_video_java.annotation.IsRole;
import com.cl.short_video_java.annotation.Log;
import com.cl.short_video_java.annotation.Login;
import com.cl.short_video_java.common.Const;
import com.cl.short_video_java.common.Result;
import com.cl.short_video_java.menum.BusinessType;
import com.cl.short_video_java.service.VideoAdService;
import com.cl.short_video_java.vo.video.Advertis;
import com.cl.short_video_java.vo.video.AdvertisSearch;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/admin/ad")
public class AdvertiseController {
	private VideoAdService videoAdService;

	public AdvertiseController(VideoAdService videoAdService) {
		this.videoAdService = videoAdService;
	}

	/**
	 * 分页查询
	 *
	 * @param advertisSearch
	 * @return
	 */
	@PostMapping("/page")
	@Login(issuer = Const.GRADE_ADMIN)
	@IsRole(menuId = 20)
	public Result getPage(@RequestBody AdvertisSearch advertisSearch) {
		return Result.success(videoAdService.getPageService(advertisSearch));
	}

	/**
	 * 删除
	 *
	 * @param idlist
	 * @return
	 */
	@PostMapping("/del")
	@Login(issuer = Const.GRADE_ADMIN)
	@IsRole(menuId = 20)
	@Log(title = "审核删除",businessType = BusinessType.DELETE)
	public Result deleteAdvertis(@RequestParam("idlist") String idlist) {
		return Result.success(videoAdService.deleteAdvertisService(idlist));
	}

	/**
	 * 修改广告位置
	 *
	 * @param position
	 * @param idlist
	 * @return
	 */
	@PostMapping("/updata")
	@Login(issuer = Const.GRADE_ADMIN)
	@IsRole(menuId = 21)
	@Log(title = "广告位置",businessType = BusinessType.UPDATE)
	public Result updataPosition(@RequestParam("position") Integer position, @RequestParam("idlist") String idlist) {
		return Result.success(videoAdService.updataPosition(position, idlist));
	}

	/**
	 * 禁用---解禁
	 *
	 * @param id
	 * @param status
	 * @return
	 */
	@PostMapping("/set")
	@Login(issuer = Const.GRADE_ADMIN)
	@Log(title = "广告解禁/禁用",businessType = BusinessType.UPDATE)
	@IsRole(menuId = 21)
	public Result setStatus(@RequestParam("id") Integer id, @RequestParam("status") Integer status) {
		return Result.success(videoAdService.setStatusService(id, status));
	}

	@PostMapping("/add")
	@Log(title = "广告新增", businessType = BusinessType.INSERT)
	@Login(issuer = Const.GRADE_ADMIN)
	@IsRole(menuId = 21)
	public Result add(@Validated @RequestBody Advertis advertis) {
		System.out.println(advertis);
		videoAdService.add(advertis);
		return Result.success();

	}
}
